using System;
using System.Collections.Generic;

namespace OffsetPath
{
    // classe s profilo
    public class OffsetProfilo2D : ClassAk
    {
        protected ClassAb a;
        protected List<ClassAb> b; // ab linea
        protected ClassO_List_LineArco c;

        public OffsetProfilo2D()
        {
            this.c = new ClassO_List_LineArco();
            this.a = new ClassAb();
            this.b = new List<ClassAb>();
        }

        public OffsetProfilo2D(OffsetProfilo2D A_0)
        {
            this.c = new ClassO_List_LineArco();
            this.a = new ClassAb();
            this.b = new List<ClassAb>();
            this.MethodA(A_0);
        }

        public bool MethodA(ClasseBaseLineaArcoClassAf A_0)
        {
            if (!this.d(A_0.h()))
            {
                return false;
            }
            ClassAq classAq = new ClassAq();
            return !this.MethodA(A_0, classAq);
        }

        public bool MethodA(PolygonalShape A_0)
        {
            return A_0.e(this);
        }

        public void MethodA(ClassO_List_LineArco A_0)
        {
            this.GetListaLineaArco().MethodA((List<ClasseBaseLineaArcoClassAf>) A_0);
            this.ab();
            this.y();
        }

        public void MethodA(OffsetProfilo2D A_0)
        {
            this.e();
            this.GetListaLineaArco().MethodA((List<ClasseBaseLineaArcoClassAf>) A_0.GetListaLineaArco());
            this.z().g(A_0.z());
            for (int i = 0; i < A_0.w().Count; i++)
            {
                this.w().Add(new ClassAb(A_0.w()[i]));
            }
        }

        public bool MethodA(ForseLineaClassA classA0, ClassAq A_1)
        {
            double num = classA0.a.MethodC(this.z().MethodB());
            ForseLineaClassA classA = new ForseLineaClassA(classA0);
            classA.b.MethodA((double) ((num + this.z().l()) + this.z().n()));
            return this.MethodA((ClasseBaseLineaArcoClassAf) classA, (List<PuntoDueD>) A_1);
        }

        public bool MethodA(ClasseBaseLineaArcoClassAf A_0, List<PuntoDueD> A_1)
        {
            ClassAb classAb = new ClassAb();
            A_0.f(classAb);
            if (!this.z().e(classAb))
            {
                return false;
            }
            if (this.GetListaLineaArco().Count != this.w().Count)
            {
                return false;
            }
            ClassAq classAq = new ClassAq();
            bool flag = false;
            for (int i = 0; i < this.GetListaLineaArco().Count; i++)
            {
                if (this.w()[i].e(classAb) && this.GetListaLineaArco()[i].MethodB(A_0, classAq))
                {
                    flag = true;
                }
            }
            A_1.InsertRange(0, classAq);
            return flag;
        }

        public bool MethodA(OffsetProfilo2D A_0, List<PuntoDueD> A_1)
        {
            if (!this.z().e(A_0.z()))
            {
                return false;
            }
            List<PuntoDueD> list = new List<PuntoDueD>();
            List<int> list2 = new List<int>();
            List<int> list3 = new List<int>();
            this.GetListaLineaArco().MethodA(A_0.GetListaLineaArco(), list, list2, list3, this.z(), A_0.z());
            bool flag = list.Count > 0;
            A_1.InsertRange(0, list);
            return flag;
        }

        public bool MethodA(PuntoDueD A_0, double A_1)
        {
            ClassAb classAb = new ClassAb(this.z());
            classAb.h(A_1);
            if (classAb.d(A_0))
            {
                if (this.GetListaLineaArco().Count == 0)
                {
                    return false;
                }
                if (this.GetListaLineaArco()[0].h().MethodC(A_0) < A_1)
                {
                    return true;
                }
                if (this.d(A_0))
                {
                    return true;
                }
                for (int i = 1; i < this.GetListaLineaArco().Count; i++)
                {
                    if (this.GetListaLineaArco()[i].MethodC(A_0) < A_1)
                    {
                        return true;
                    }
                }
            }
            return false;
        }

        public void MethodA(OffsetProfilo2D A_0, List<PolygonalShape> A_1, ClassAg A_2)
        {
            this.MethodA(A_0, A_1, false, true, A_2);
        }

        public double MethodA(OffsetProfilo2D A_0, PuntoDueD A_1, PuntoDueD A_2)
        {
            if (this.GetListaLineaArco().Count == 0)
            {
                return 0.0;
            }
            if (A_0.GetListaLineaArco().Count == 0)
            {
                return 0.0;
            }
            if (A_0.w().Count != A_0.GetListaLineaArco().Count)
            {
                return 0.0;
            }
            if (this.GetListaLineaArco().Count != this.w().Count)
            {
                return 0.0;
            }
            int num = 0;
            ClassAb classAb = A_0.z();
            double num2 = this.w()[0].MethodA(classAb);
            for (int i = 1; i < this.w().Count; i++)
            {
                double num4 = this.w()[i].MethodA(classAb);
                if (num4 < num2)
                {
                    num2 = num4;
                    num = i;
                }
            }
            int num5 = 0;
            num2 = A_0.w()[0].MethodA(this.w()[num]);
            for (int j = 1; j < A_0.w().Count; j++)
            {
                double num7 = A_0.w()[j].MethodA(this.w()[num]);
                if (num7 < num2)
                {
                    num2 = num7;
                    num5 = j;
                }
            }
            double num8 = this.GetListaLineaArco()[num].e(A_0.GetListaLineaArco()[num5], A_1, A_2);
            if (num8 == 0.0)
            {
                return 0.0;
            }
            PuntoDueD puntoDueD = new PuntoDueD();
            PuntoDueD x2 = new PuntoDueD();
            for (int k = 0; k < this.GetListaLineaArco().Count; k++)
            {
                if (this.w()[k].MethodA(classAb) < num8)
                {
                    for (int m = 0; m < A_0.GetListaLineaArco().Count; m++)
                    {
                        double num11 = this.GetListaLineaArco()[k].e(A_0.GetListaLineaArco()[m], puntoDueD, x2);
                        if (num11 < num8)
                        {
                            A_1.e(puntoDueD);
                            A_2.e(x2);
                            if (num11 == 0.0)
                            {
                                return 0.0;
                            }
                            num8 = num11;
                        }
                    }
                }
            }
            if (this.z().c(A_0.z()) && this.d(x2))
            {
                return (num8 * -1.0);
            }
            if (A_0.z().c(this.z()) && A_0.d(puntoDueD))
            {
                num8 *= -1.0;
            }
            return num8;
        }

        public void MethodA(ClassAq A_0, List<int> A_1, ClassV A_2, bool A_3, bool A_4)
        {
            if (A_1.Count == A_0.Count)
            {
                ClassV classV = new ClassV();
                if (this.c.Count >= 1)
                {
                    A_0.a(A_1);
                    bool flag = A_3;
                    if (flag == A_4)
                    {
                        classV.Add(new ClassO_List_LineArco());
                    }
                    int num = 0;
                    for (int i = 0; i < this.GetListaLineaArco().Count; i++)
                    {
                        ClassAq classAq = new ClassAq();
                        while ((num < A_1.Count) && (A_1[num] == i))
                        {
                            classAq.a(A_0[num]);
                            num++;
                        }
                        if (classAq.Count > 0)
                        {
                            ClassO_List_LineArco classO = new ClassO_List_LineArco();
                            this.GetListaLineaArco()[i].j(classAq, classO);
                            while (classO.Count > 1)
                            {
                                if (flag == A_4)
                                {
                                    classV[classV.Count - 1].Add(classO.MethodA(0));
                                    flag = !A_4;
                                }
                                else
                                {
                                    classV.Add(new ClassO_List_LineArco());
                                    flag = A_4;
                                    classO.RemoveAt(0);
                                }
                            }
                            if (flag == A_4)
                            {
                                classV[classV.Count - 1].Add(classO.MethodA((int) (classO.Count - 1)));
                            }
                            else
                            {
                                classO.RemoveAt(classO.Count - 1);
                            }
                        }
                        else if (flag == A_4)
                        {
                            classV[classV.Count - 1].MethodA(this.GetListaLineaArco()[i]);
                        }
                    }
                    A_2.a((List<ClassO_List_LineArco>) classV);
                }
            }
        }

        public void MethodA(OffsetProfilo2D A_0, List<PolygonalShape> A_1, bool A_2, bool A_3, ClassAg A_4)
        {
            if (this.z().e(A_0.z()))
            {
                switch (A_4.c)
                {
                    case ClassAg.EnumA.a:
                        {
                            ClassV classV = new ClassV();
                            ClassV v2 = new ClassV();
                            MethodA(this, A_2, A_0, A_3, classV, v2);
                            classV.a((List<ClassO_List_LineArco>) v2);
                            if (classV.Count > 0)
                            {
                                classV.a();
                                List<OffsetProfilo2D> list = new List<OffsetProfilo2D>();
                                for (int i = classV.Count - 1; i >= 0; i--)
                                {
                                    if (classV[i].MethodA(true) && (classV[i].Count > 2))
                                    {
                                        list.Add(new OffsetProfilo2D());
                                        list[list.Count - 1].MethodB(classV[i]);
                                    }
                                    else
                                    {
                                        A_4.MethodD();
                                    }
                                }
                                ContenitoreLivello contenitoreLivello = new ContenitoreLivello();
                                if (!A_2 || !A_3)
                                {
                                    PolygonalShape.MethodA1(contenitoreLivello, list);
                                    if (contenitoreLivello.Count != 1)
                                    {
                                        A_4.MethodD();
                                    }
                                }
                                else
                                {
                                    for (int k = 0; k < list.Count; k++)
                                    {
                                        A_1.Add(new PolygonalShape(list[k]));
                                    }
                                }
                                for (int j = 0; j < contenitoreLivello.Count; j++)
                                {
                                    A_1.Add(contenitoreLivello[j]);
                                }
                            }
                            break;
                        }
                    case ClassAg.EnumA.b:
                        {
                            OffsetProfilo2D s3 = new OffsetProfilo2D(A_0);
                            s3.x();
                            A_4.c = ClassAg.EnumA.a;
                            this.MethodA(s3, A_1, A_2, A_3, A_4);
                            A_4.c = ClassAg.EnumA.b;
                            return;
                        }
                    case ClassAg.EnumA.c:
                        {
                            ClassAb classAb = new ClassAb();
                            if (this.z().MethodA(A_0.z(), classAb))
                            {
                                A_4.MethodB();
                                A_4.MethodB(classAb, false);
                                A_4.c = ClassAg.EnumA.d;
                                this.MethodA(A_0, A_1, A_2, A_3, A_4);
                                A_4.c = ClassAg.EnumA.c;
                            }
                            return;
                        }
                    case ClassAg.EnumA.d:
                        {
                            OffsetProfilo2D offsetProfilo2D = new OffsetProfilo2D(this);
                            OffsetProfilo2D s2 = new OffsetProfilo2D(A_0);
                            offsetProfilo2D.n(A_4);
                            s2.n(A_4);
                            ClassAtPuntoIncrementale classAt = new ClassAtPuntoIncrementale(offsetProfilo2D.z().GetEndPnt(), s2.z().GetEndPnt());
                            double num = A_4.MethodB();
                            if (classAt.a > 0.0)
                            {
                                classAt.a = num;
                            }
                            else
                            {
                                classAt.a = -num;
                            }
                            if (classAt.b > 0.0)
                            {
                                classAt.b = num;
                            }
                            else
                            {
                                classAt.b = -num;
                            }
                            classAt.a *= 0.411923;
                            classAt.b *= 0.313131;
                            s2.p(classAt);
                            A_4.c = ClassAg.EnumA.a;
                            offsetProfilo2D.MethodA(s2, A_1, A_2, A_3, A_4);
                            for (int m = 0; m < A_1.Count; m++)
                            {
                                A_1[m].MethodA1(A_4);
                            }
                            A_4.c = ClassAg.EnumA.d;
                            return;
                        }
                    case ClassAg.EnumA.e:
                        {
                            OffsetProfilo2D s4 = new OffsetProfilo2D(A_0);
                            ClassAtPuntoIncrementale at2 = new ClassAtPuntoIncrementale(this.z().GetEndPnt(), s4.z().GetEndPnt());
                            double num5 = A_4.MethodB();
                            if (at2.a > 0.0)
                            {
                                at2.a = num5;
                            }
                            else
                            {
                                at2.a = -num5;
                            }
                            if (at2.b > 0.0)
                            {
                                at2.b = num5;
                            }
                            else
                            {
                                at2.b = -num5;
                            }
                            at2.a *= 0.411923;
                            at2.b *= 0.313131;
                            s4.p(at2);
                            A_4.c = ClassAg.EnumA.a;
                            this.MethodA(s4, A_1, A_2, A_3, A_4);
                            for (int n = 0; n < A_1.Count; n++)
                            {
                                A_1[n].MethodA1(A_4);
                            }
                            A_4.c = ClassAg.EnumA.e;
                            return;
                        }
                    default:
                        return;
                }
            }
        }

        public static void MethodA(OffsetProfilo2D A_0, bool A_1, OffsetProfilo2D A_2, bool A_3, ClassV A_4, ClassV A_5)
        {
            ClassAq classAq = new ClassAq();
            List<int> list = new List<int>();
            List<int> list2 = new List<int>();
            A_0.GetListaLineaArco().MethodA(A_2.GetListaLineaArco(), classAq, list, list2, A_0.z(), A_2.z());
            ClassAq aq2 = new ClassAq();
            aq2.a((List<PuntoDueD>) classAq);
            bool flag = A_2.d(A_0.GetListaLineaArco()[0].h());
            bool flag2 = A_0.d(A_2.GetListaLineaArco()[0].h());
            if (((classAq.Count != 0) || flag) || flag2)
            {
                A_0.MethodA(classAq, list, A_4, flag, A_1);
                A_2.MethodA(aq2, list2, A_5, flag2, A_3);
            }
        }

        protected void aa()
        {
            this.GetListaLineaArco().b();
            this.ab();
        }

        protected void ab()
        {
            this.w().Clear();
            for (int i = 0; i < this.GetListaLineaArco().Count; i++)
            {
                ClassAb classAb = new ClassAb();
                this.GetListaLineaArco()[i].f(classAb);
                this.w().Add(classAb);
            }
        }

        public ClassO_List_LineArco GetListaLineaArco()
        {
            return this.c;
        }

        public double ad()
        {
            double num = 0.0;
            for (int i = 0; i < this.GetListaLineaArco().Count; i++)
            {
                num += this.GetListaLineaArco()[i].g();
            }
            return num;
        }

        public bool MethodB(ClasseBaseLineaArcoClassAf A_0)
        {
            ClassAb classAb = new ClassAb();
            A_0.f(classAb);
            List<PuntoDueD> list = new List<PuntoDueD>();
            for (int i = 0; i < this.GetListaLineaArco().Count; i++)
            {
                if (this.w()[i].e(classAb) && this.GetListaLineaArco()[i].MethodB(A_0, list))
                {
                    return true;
                }
            }
            return false;
        }

        public void MethodB(ClassO_List_LineArco A_0)
        {
            this.GetListaLineaArco().Clear();
            this.GetListaLineaArco().AggiungiElementiLineaArco(A_0);
            this.ab();
            this.y();
        }

        public bool MethodB(OffsetProfilo2D A_0)
        {
            if (A_0.GetListaLineaArco().Count == 0)
            {
                return false;
            }
            if (!this.z().c(A_0.z()))
            {
                return false;
            }
            if (!this.d(A_0.GetListaLineaArco()[0].h()))
            {
                return false;
            }
            return !this.MethodC(A_0);
        }

        public void MethodB(OffsetProfilo2D A_0, List<PolygonalShape> A_1, ClassAg A_2)
        {
            this.MethodA(A_0, A_1, false, false, A_2);
        }

        public double MethodC(ClasseBaseLineaArcoClassAf A_0)
        {
            if (this.GetListaLineaArco().Count == 0)
            {
                return 0.0;
            }
            PuntoDueD puntoDueD = new PuntoDueD();
            PuntoDueD x2 = new PuntoDueD();
            double num = this.GetListaLineaArco()[0].e(A_0, puntoDueD, x2);
            for (int i = 1; i < this.GetListaLineaArco().Count; i++)
            {
                double num3 = this.GetListaLineaArco()[i].e(A_0, puntoDueD, x2);
                if (num3 == 0.0)
                {
                    return 0.0;
                }
                if (num3 < num)
                {
                    num = num3;
                }
            }
            if (this.d(A_0.h()))
            {
                return -num;
            }
            return num;
        }

        public bool MethodC(OffsetProfilo2D A_0)
        {
            if (this.z().e(A_0.z()))
            {
                List<PuntoDueD> list = new List<PuntoDueD>();
                for (int i = 0; i < this.GetListaLineaArco().Count; i++)
                {
                    if (A_0.MethodA(this.GetListaLineaArco()[i], list))
                    {
                        return true;
                    }
                }
            }
            return false;
        }

        public override double MethodC(PuntoDueD A_0)
        {
            if (this.GetListaLineaArco().Count == 0)
            {
                return 0.0;
            }
            double num = this.GetListaLineaArco()[0].MethodC(A_0);
            for (int i = 1; i < this.GetListaLineaArco().Count; i++)
            {
                double num3 = this.GetListaLineaArco()[i].MethodC(A_0);
                if (num3 < num)
                {
                    num = num3;
                }
            }
            if (this.d(A_0))
            {
                return -num;
            }
            return num;
        }

        public void MethodC(OffsetProfilo2D A_0, List<PolygonalShape> A_1, ClassAg A_2)
        {
            this.MethodA(A_0, A_1, true, true, A_2);
        }

        public bool d(OffsetProfilo2D A_0)
        {
            if ((this.GetListaLineaArco().Count == 0) || (A_0.GetListaLineaArco().Count == 0))
            {
                return false;
            }
            if (!A_0.d(this.GetListaLineaArco()[0].i()) && !this.MethodC(A_0))
            {
                return this.d(A_0.GetListaLineaArco()[0].i());
            }
            return true;
        }

        public bool d(PuntoDueD A_0)
        {
            if (!this.z().d(A_0))
            {
                return false;
            }
            ClassAq classAq = new ClassAq();
            ForseLineaClassA classA = new ForseLineaClassA(A_0, new ClassAtPuntoIncrementale(this.z().l(), 1E-06));
            if (!this.MethodA((ClasseBaseLineaArcoClassAf) classA, (List<PuntoDueD>) classAq))
            {
                return false;
            }
            classAq.c(classA.a);
            if (!classAq[0].MethodB(A_0))
            {
                return ((classAq.Count & 1) > 0);
            }
            return true;
        }

        public void e()
        {
            this.z().j();
            this.GetListaLineaArco().Clear();
            this.w().Clear();
        }

        public override void f(ClassAb A_0)
        {
            A_0.g(this.z());
        }

        ~OffsetProfilo2D()
        {
        }

        public override void k(ForseLineaClassA classA0, ClassAj A_1)
        {
            if (this.GetListaLineaArco().Count != 0)
            {
                this.GetListaLineaArco()[0].k(classA0, A_1);
                for (int i = 1; i < this.GetListaLineaArco().Count; i++)
                {
                    ClassAj classAj = new ClassAj();
                    this.GetListaLineaArco()[i].k(classA0, classAj);
                    A_1.MethodB(classAj);
                }
            }
        }

        public override void l(ClassAtPuntoIncrementale A_0, ClassAj A_1)
        {
            if (this.GetListaLineaArco().Count != 0)
            {
                this.GetListaLineaArco()[0].l(A_0, A_1);
                for (int i = 1; i < this.GetListaLineaArco().Count; i++)
                {
                    ClassAj classAj = new ClassAj();
                    this.GetListaLineaArco()[i].l(A_0, classAj);
                    A_1.MethodB(classAj);
                }
            }
        }

        public override void n(ClassAg A_0)
        {
            for (int i = 0; i < this.c.Count; i++)
            {
                this.c[i].n(A_0);
            }
            for (int j = 0; j < this.b.Count; j++)
            {
                this.b[j].n(A_0);
            }
            this.z().n(A_0);
        }

        public override void o(double A_0, PuntoDueD A_1)
        {
            if (this.GetListaLineaArco().Count == this.w().Count)
            {
                for (int i = 0; i < this.GetListaLineaArco().Count; i++)
                {
                    this.GetListaLineaArco()[i].o(A_0, A_1);
                    this.GetListaLineaArco()[i].f(this.w()[i]);
                }
                this.z().o(A_0, A_1);
            }
        }

        public override void p(ClassAtPuntoIncrementale A_0)
        {
            if (this.GetListaLineaArco().Count == this.w().Count)
            {
                for (int i = 0; i < this.GetListaLineaArco().Count; i++)
                {
                    this.GetListaLineaArco()[i].p(A_0);
                    this.w()[i].p(A_0);
                }
                this.z().p(A_0);
            }
        }

        public override void q(ForseLineaClassA classA0)
        {
            if (this.GetListaLineaArco().Count == this.w().Count)
            {
                for (int i = 0; i < this.GetListaLineaArco().Count; i++)
                {
                    this.GetListaLineaArco()[i].q(classA0);
                }
                this.aa();
                this.z().q(classA0);
            }
        }

        public override void r(PuntoDueD A_0)
        {
            if (this.GetListaLineaArco().Count == this.w().Count)
            {
                for (int i = 0; i < this.GetListaLineaArco().Count; i++)
                {
                    this.GetListaLineaArco()[i].r(A_0);
                }
                this.aa();
                this.z().r(A_0);
            }
        }

        public override void GetStartPoint(double A_0, PuntoDueD A_1)
        {
            if (this.GetListaLineaArco().Count == this.w().Count)
            {
                for (int i = 0; i < this.GetListaLineaArco().Count; i++)
                {
                    this.GetListaLineaArco()[i].GetStartPoint(A_0, A_1);
                    this.GetListaLineaArco()[i].f(this.w()[i]);
                }
                this.y();
            }
        }

        public bool u()
        {
            return this.GetListaLineaArco().MethodA();
        }

        public bool v()
        {
            return this.GetListaLineaArco().MethodA(false);
        }

        public List<ClassAb> w()
        {
            return this.b;
        }

        public void x()
        {
            PuntoDueD puntoDueD = this.z().d();
            double num = Math.Max(puntoDueD.X, puntoDueD.Y) * ClassK.e;
            ClassAm classAm = new ClassAm(num * 10.0, num * 100.0);
            ClassAtPuntoIncrementale classAt = new ClassAtPuntoIncrementale(classAm.MethodA(), classAm.MethodA());
            if (classAm.e())
            {
                classAt.a = -classAt.a;
            }
            if (classAm.e())
            {
                classAt.b = -classAt.b;
            }
            this.p(classAt);
        }

        protected void y()
        {
            if (this.w().Count == 0)
            {
                this.z().j();
            }
            else
            {
                this.z().g(this.w()[0]);
                for (int i = 1; i < this.w().Count; i++)
                {
                    this.z().d(this.w()[i]);
                }
            }
        }

        public ClassAb z()
        {
            return this.a;
        }
    }
}

